package com.daixin.blog.dto;

import lombok.Data;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * Author daixin
 */
@Component
@Data
public class PageinationDTO {
    private List<QuestionDTO> questions;
    private boolean showPrevious;
    private boolean showFirstPage;
    private boolean showNext;
    private boolean showEndPage;
    private Integer page;                   //当前页
    private List<Integer> pages = new ArrayList<>();
    private  Integer totalPage;         //计算应显示的总页数
    public void setPageinationDTO(Integer totalPage,Integer page) {
        this.totalPage = totalPage;
        this.page = page;
        //使分页显示当前页的前三页
        pages.add(page);
        for (int i = 1; i <=3; i++) {
            if(page - i >0){
                pages.add(0, page - i);
            }
            if(page+i <= totalPage){
                pages.add(page + i);
            }
        }

    }
}
